package com.open.capacity.reimburse.controller;

import java.util.Map;

import com.open.capacity.commons.Result;
import io.swagger.annotations.Api;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.security.access.prepost.PreAuthorize;
import com.open.capacity.reimburse.entity.BaseSetMode;
import com.open.capacity.reimburse.service.BaseSetModeService;

import com.open.capacity.commons.PageResult;
import javax.validation.Valid;
/**
 * 结算方式
 *
 * @author 
 * @email 
 * @date 2023-11-01 08:54:50
 */
@RestController
@RequestMapping("basesetmodes")
@Api(tags = "结算方式")
public class BaseSetModeController {

    @Autowired
    private BaseSetModeService baseSetModeService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @PreAuthorize("hasAnyAuthority('base_set_mode:basesetmode:list')")
    public PageResult list(@RequestParam Map<String, Object> params) {
        PageResult pageResult = baseSetModeService.pageAll(params);
        return pageResult;
    }

    /**
    * 查询单条记录
    */
    @RequestMapping("/findById")
    @PreAuthorize("hasAnyAuthority('base_set_mode:basesetmode:list')")
    public Result findById(String id) {
        return Result.succeed(baseSetModeService.findById(id));
    }

    /**
     * 保存
     */
    @RequestMapping("/saveOrUpdate")
    @PreAuthorize("hasAnyAuthority('base_set_mode:basesetmode:save')")
    public Result save(@RequestBody @Valid  BaseSetMode baseSetMode, String keyValue) {
    	 if(StringUtils.isEmpty(keyValue)) {
              baseSetModeService.save(baseSetMode);
	     }else {
          baseSetMode.setId(keyValue);
          baseSetModeService.update(baseSetMode);
	     }
        return Result.succeed("保存成功");
    }


    /**
     * 删除
     */
    @DeleteMapping("/delete/{id}")
    @PreAuthorize("hasAnyAuthority('base_set_mode:basesetmode:delete')")
    public Result delete(@PathVariable String  id) {
            baseSetModeService.delete(id);
        return Result.succeed("删除成功");
    }

}
